package functions;

import connection.*;

public class BasicFunctions implements IrcFunction {
	IrcConnection connection;
	
	public BasicFunctions() {
	}
	public void setIrcConnection(IrcConnection con) {
		connection = con;
		connection.addEventListener(this, "PRIVMSG");
	}
	
	public void setParams(String[] params) {
	}
	
	public void eventPerformed(IrcEvent e) {
		String cmd = e.getFirstWord();
		if (cmd.equals(",echo")) {
			connection.privMsg(e.getTarget(), e.getPrivRest());
		
		} else if (cmd.equals(",join")) {
			String[] channels = e.getPrivRest().split(" ");
			for (String s: channels) {
				connection.join(s);
			}
			
		} else if (cmd.equals(",quit")) {
			connection.quit();
		
		} else if (cmd.equals(",part")) {
			// TODO ,part
			
		} else if (cmd.equals(",ping")) {
			connection.privMsg(e.getTarget(), "pong!");
		} else if (cmd.equals(",query")) {
			connection.query(e.getPrivRest());
		}
	}
}
